package com.vueapi.service.impl;

import com.vueapi.domain.HjUser;
import com.vueapi.domain.HjWebsite;
import com.vueapi.domain.vo.WebBlogInfoVo;
import com.vueapi.domain.vo.WebCountVo;
import com.vueapi.domain.vo.WebWebsiteVo;
import com.vueapi.service.*;
import com.vueapi.utils.ResultUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Classname WebIndexServiceImpl
 * @Description TODO
 * @Created by 赵宏建
 * @Date 2022/9/27 11:19
 * @Version 1.0.0
 */
@Service
public class WebIndexServiceImpl implements WebIndexService {

    @Resource
    private HjUserService userService;

    @Resource
    private HjWebsiteService websiteService;

    @Resource
    private HjArticleService articleService;

    @Resource
    private HjTagService tagService;

    @Resource
    private HjCategoryService categoryService;

    @Override
    public ResultUtils getBlogInfo() {
        HjUser user = userService.getById(1);
        HjWebsite website = websiteService.getById(1);

        // count
        WebCountVo webCountVo = new WebCountVo();
        // 总访问量 viewCounts
        webCountVo.setViewCounts(website.getViewCount());
        // 文章数量 articleCount
        webCountVo.setArticleCount(articleService.getCount());
        // 分类数量 categoryCount
        webCountVo.setCategoryCount(categoryService.getCount());
        // 标签数量 tagCount
        webCountVo.setTagCount(tagService.getCount());

        // website
        WebWebsiteVo websiteVo = new WebWebsiteVo();
        // 公告 bulletin
        websiteVo.setBulletin(website.getBulletin());
        // 作者头像 authorAvatar
        websiteVo.setAuthorAvatar(user.getAvatar());
        // 作者名称 author
        websiteVo.setAuthor(user.getNickname());
        // 作者信息 authorInfo
        websiteVo.setAuthorInfo(user.getSignature());
        // 作者QQ
        websiteVo.setQQ(user.getQq());
        // 作者邮箱
        websiteVo.setEmail(user.getEmail());
        // 作者 github
        websiteVo.setGithub(user.getGithub());
        // 作者 gitee
        websiteVo.setGitee(user.getGitee());

        WebBlogInfoVo blogInfoVo = new WebBlogInfoVo();
        blogInfoVo.setCount(webCountVo);
        blogInfoVo.setWebSite(websiteVo);

        return ResultUtils.success(blogInfoVo);
    }
}
